package com.Wlongtao.eBusiness.cotroller;

import com.Wlongtao.eBusiness.dao.GameRepository;
import com.Wlongtao.eBusiness.dao.PlayerRepository;
import com.Wlongtao.eBusiness.dto.PlayerProject;
import com.Wlongtao.eBusiness.entity.Game;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

@Controller

public class HomeController {

    @Value("${version}")
    private String version;

    @Autowired
    GameRepository gameRepository;

    @Autowired
    PlayerRepository playerRepository;

    @GetMapping("/")
    public String displayHome(Model model){

        model.addAttribute("versionNumber",version);

        List<Game> games= gameRepository.findAll();
        model.addAttribute("games",games);

        List<PlayerProject> playerProjects = playerRepository.playerProjects();
        model.addAttribute("playerProjects",playerProjects);

        return "main/game";
    }

}
